package com.partners.service.Impl;

import com.partners.configure.TokenConfig;
import com.partners.dao.basic.UserDao;
import com.partners.dao.bo.UserDO;
import com.partners.model.Member;
import com.partners.model.TokenCodeModel;
import com.partners.service.TokenServer;
import com.partners.utils.ApiResultUtil;
import com.partners.utils.SessionManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author liangyongle
 * @date 2019-01-14
 */
@Service
@Slf4j
public class TokenServerImpl implements TokenServer {


    @Resource
    private SessionManager sessionManager;

    @Resource
    private TokenConfig tokenConfig;

    @Resource
    private UserDao userDao;
    /**
     * 生成token
    * */
    @Override
    public Member createToken(Integer uid) {
        Member member = new Member();
        UserDO userDO = userDao.selectByPrimaryKey(uid);

        String token = UUID.randomUUID().toString();
        member.setToken("adadasasds");
        member.setOpenId("kasdkajdkajdasd");
        member.setName("Forever");
        member.setId(123456);
        log.info("token:{}",member);
//        tokenSesson.updateMemberTokenContent(token,member);
//
//        return ApiResultUtil.ok(token);
        return null;
//        Member member = new Member();
//        member.setId(123456);
//        member.setName("Forever");
//        member.setOpenId(openId);
//        String token = sessionManager.saveAndCreateTokens(member);
//        Map<String,Object> maps = new HashMap<>();
//        maps.put("token",token);
//        return maps;
    }

/*    @Override
    public Member getMemberByToken(String token) {
        return null;
    }


    //  生成token
    @Override
    public TokenCodeModel createAndSaveToken(String openId) {

        Member fans = new Member();
        fans.setId(123456);
        fans.setName("Forever");
        fans.setOpenId(openId);
        String tokens = UUID.randomUUID().toString();
        fans.setToken(tokens);
        TokenCodeModel tokenCodeModel = tokenConfig.createAndSaveToken(fans);
        log.info("tokens{}",tokenCodeModel);
        return tokenCodeModel;
    }*/
}
